package view.manage;

import connectivity.QueryManager;
import main.WinkelApplication;
import model.User;
/**
 *
 * @author JJ Zeilmaker
 */
public class Main extends javax.swing.JPanel {

    /** Creates new form view */
    public Main() {
        initComponents();
        
        /*
           Sets all labels visible false default for security.
         * 
         */
        lblReports.setVisible(false);
        lblCatalogus.setVisible(false);
        lblInventory.setVisible(false);
        lblSystemUsers.setVisible(false);
        lblCustomers.setVisible(false);       
        
        setMenuPermissions();
    }
    
    /*
      Function to getUser rol_id.
     * Use rol_id to see what promissions acquired
     * show menu option`s to promissions user has
     */
    public void setMenuPermissions(){    
        
        User user = WinkelApplication.getUser();
        int p = user.getRol_id();
        
        boolean showWelcomeMsg = false;

        switch(p) {                   
            case 2:  // Medewerker
                lblCustomers.setVisible(true);
                showWelcomeMsg = true;
                     break;
            case 3:  // Manager
                lblReports.setVisible(true);
                lblCatalogus.setVisible(true);
                lblInventory.setVisible(true);
                lblCustomers.setVisible(true);  
                showWelcomeMsg = true;
                     break;
            case 4:  // Administrator
                lblSystemUsers.setVisible(true);
                showWelcomeMsg = true;
                     break;                
        }
        if(showWelcomeMsg){
           String usrName = user.getGebruikersnaam();
           lblWelcomeUsr.setText("Welkom, " + usrName);     
        }
             
    }

    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        lblSystemUsers = new javax.swing.JLabel();
        lblCatalogus = new javax.swing.JLabel();
        lblInventory = new javax.swing.JLabel();
        lblCustomers = new javax.swing.JLabel();
        lblReports = new javax.swing.JLabel();
        btnLogOut = new javax.swing.JButton();
        lblWelcomeUsr = new javax.swing.JLabel();

        jButton1.setText("jButton1");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("Beheer");

        lblSystemUsers.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblSystemUsers.setText("Systeem gebruikers");
        lblSystemUsers.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblSystemUsers.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblSystemUsersMouseClicked(evt);
            }
        });

        lblCatalogus.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblCatalogus.setText("Catalogus");
        lblCatalogus.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblCatalogus.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblCatalogusMouseClicked(evt);
            }
        });

        lblInventory.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblInventory.setText("Vooraad");
        lblInventory.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblInventory.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblInventoryMouseClicked(evt);
            }
        });

        lblCustomers.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblCustomers.setText("Klanten");
        lblCustomers.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblCustomers.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblCustomersMouseClicked(evt);
            }
        });

        lblReports.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblReports.setText("Rapporten");
        lblReports.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblReports.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblReportsMouseClicked(evt);
            }
        });

        btnLogOut.setText("Log uit");
        btnLogOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLogOutActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnLogOut, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 712, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 556, Short.MAX_VALUE)
                        .addComponent(lblWelcomeUsr, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblCustomers)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblSystemUsers)
                        .addGap(18, 18, 18)
                        .addComponent(lblCatalogus)
                        .addGap(18, 18, 18)
                        .addComponent(lblInventory)
                        .addGap(18, 18, 18)
                        .addComponent(lblReports)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(lblWelcomeUsr, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblCustomers)
                            .addComponent(lblSystemUsers)
                            .addComponent(lblCatalogus)
                            .addComponent(lblInventory)
                            .addComponent(lblReports))
                        .addGap(382, 382, 382))
                    .addComponent(btnLogOut))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void lblInventoryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblInventoryMouseClicked
           WinkelApplication.window.newWindow(new view.manage.inventory.InventoryList());
    }//GEN-LAST:event_lblInventoryMouseClicked

    private void lblCustomersMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblCustomersMouseClicked
                WinkelApplication.window.newWindow(new view.manage.customers.CustomerOversight());
    }//GEN-LAST:event_lblCustomersMouseClicked

    private void lblReportsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblReportsMouseClicked
                WinkelApplication.window.newWindow(new view.manage.reports.view());
    }//GEN-LAST:event_lblReportsMouseClicked

    private void lblCatalogusMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblCatalogusMouseClicked

        WinkelApplication.window.newWindow(new view.manage.inventory.Catalog());     }//GEN-LAST:event_lblCatalogusMouseClicked

    private void lblSystemUsersMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblSystemUsersMouseClicked

        WinkelApplication.window.newWindow(new view.manage.admin.SearchUsers());     }//GEN-LAST:event_lblSystemUsersMouseClicked

    private void btnLogOutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogOutActionPerformed
        WinkelApplication.getInstance().showPanel(new view.manage.Login());
    }//GEN-LAST:event_btnLogOutActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLogOut;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblCatalogus;
    private javax.swing.JLabel lblCustomers;
    private javax.swing.JLabel lblInventory;
    private javax.swing.JLabel lblReports;
    private javax.swing.JLabel lblSystemUsers;
    private javax.swing.JLabel lblWelcomeUsr;
    // End of variables declaration//GEN-END:variables
}
